home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / PRTxtBuf.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.7 KB  |  134 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRTxtBuf.h
  4. //    Release Version:    $ ODF 2 $
  5. //    Modifed by MEB to support non-single-byte characters
  6. //
  7. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  8. //
  9. //========================================================================================
  10.  
  11. #ifndef PRTXTBUF_H
  12. #define PRTXTBUF_H
  13.  
  14. #ifndef SLGRDEF_H
  15. #include "SLGrDef.h"
  16. #endif
  17.  
  18. // ----- Foundation Layer -----
  19.  
  20. #ifndef FWSTRING_H
  21. #include "FWString.h"
  22. #endif
  23.  
  24. #ifndef FWEXCLIB_H
  25. #include "FWExcLib.h"
  26. #endif
  27.  
  28. #ifndef SLCHARIT_H
  29. #include "SLCharIt.h"
  30. #endif
  31.  
  32. // ----- OpenDoc Includes -----
  33.  
  34. #ifndef FWODTYPS_H
  35. #include "FWODTyps.h"
  36. #endif
  37.  
  38. //========================================================================================
  39. // Forward class declarations
  40. //========================================================================================
  41.  
  42. class FW_OTextRunReader;
  43.  
  44. //========================================================================================
  45. // CLASS FW_CPrivTextBuffer
  46. //========================================================================================
  47. //    Internal class used by the graphic component to read text from strings or text readers
  48. //    for text measurement/drawing.
  49. //    Text is sliced up into lines (terminated by newLine character)
  50. //    We try to avoid dynamic memory allocation as possible
  51.  
  52. class FW_CPrivTextBuffer
  53. {
  54. public:
  55.     FW_DECLARE_AUTO(FW_CPrivTextBuffer)
  56.  
  57.     FW_CPrivTextBuffer(FW_HString string);
  58.         // Constructs a buffer using a string as a source.
  59.         // No data copying occurs.
  60.         
  61.     FW_CPrivTextBuffer(FW_HTextReader reader);
  62.         //     Constructs a buffer using a text reader as a source.
  63.         //    No data copying occurs if the first block read from the reader
  64.         //    is as large as the whole data structure;
  65.         //    otherwise, data is copied into a temporary contiguous buffer line by line.
  66.         
  67.     ~FW_CPrivTextBuffer();
  68.     
  69.     FW_Boolean             IsDone() const;
  70.         // returns TRUE when there is nothing left to read
  71.         
  72.     void                 Advance();
  73.         // reads the next line from the buffer
  74.  
  75.     void                 GetCurrentLine(const char*& pLine, FW_ByteCount& len);
  76.         // returns a pointer to the next contiguous line of text and its length
  77.  
  78. private:
  79.     void                 ResetBuffer(FW_ByteCount size = 256);
  80.     FW_Boolean            GetNextRun();
  81.     char*                FindRunNewLine();
  82.     void                AppendToBuffer(const char* pch, FW_ByteCount cb);
  83.  
  84.     FW_CPrivTextBuffer(const FW_CPrivTextBuffer& otherBuffer);
  85.     FW_CPrivTextBuffer& operator=(const FW_CPrivTextBuffer& otherBuffer);
  86.         // Copy constructor and assignment operator not valid for this class.
  87.  
  88. private:
  89.     FW_HString                 fString;
  90.     FW_HTextReader             fReader;
  91.  
  92.     char*                     fCurrentLine;
  93.     FW_ByteCount             fCurrentLineLength;
  94.  
  95.     FW_Boolean                 fIsDone;        // are we there yet?
  96.     FW_Boolean                fIsLastLine;
  97.  
  98.     char*                    fCurRun;
  99.     char*                    fCurRunPos;
  100.     FW_ByteCount            fCurRunLen;
  101.     FW_Boolean                fCurRunIsLast;
  102.  
  103.     enum { kBufferSize = 256 };
  104.     char                     fFixedBuffer[kBufferSize];
  105.  
  106.     FW_Boolean                fUsingFixedBuffer;
  107.     
  108.     char*                    fCurrentBufferBase;
  109.     FW_ByteCount            fCurrentBufferSize;
  110.  
  111.     char*                     fDynamicBufferBase;
  112.     FW_ByteCount             fDynamicBufferSize;
  113.         // if the fixed buffer is too small, we allocate a dynamic buffer
  114. };
  115.  
  116. //========================================================================================
  117. // Global Method FW_PrivGetStringSegment
  118. //========================================================================================
  119.  
  120. FW_Boolean    FW_PrivGetStringSegment(
  121.     ODPlatformCanvas        platformCanvas,
  122.     FW_Boolean&                bCalledBefore,
  123.     const char*                str,
  124.     FW_ByteCount            len,
  125.     FW_BytePosition&        segStart,
  126.     FW_ByteCount&            segLen,
  127.     FW_PlatformCoordinate    maxWidth,
  128.     FW_PlatformCoordinate&     actualWidth,
  129.     FW_Boolean                wordWrap,
  130.     FW_Boolean                wordBreak);
  131.  
  132. #endif
  133.  
  134.